package communicationMessages;

import data.Member;
import data.MemberDataBase;
import database.DB;

public class RegisterMessage extends Message {

	@Override
	public String getAnswer() {
		String ans;
		String userName,password;
		String arr[] = this.getContent().split(delimiter);
		if (arr.length == 2)
		{
			userName = arr[0];
			password = arr[1];
		}
		else
		{
			ans = "wrong format"+delimiter;
			return ans;
		}
		
		
		if (!userName.equalsIgnoreCase("guest") && DB.AddNewMember(userName, password))
		{
			ans ="Register"+delimiter+DB.getUserRoll(userName)+delimiter+"success"+delimiter;
			this.activateUser(userName);
		}

		else{
			ans = "Register"+delimiter+"guest"+delimiter+"failed"+delimiter+"user name allready exist"+delimiter;
		}
		return ans;
	}

}
